<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="二级单位名称">
              <a-select
                class="select-multiple-notExpend"
                mode="multiple"
                v-model="model.ejdw"
                :maxTagCount="1"
                style="width: 280px"
                placeholder="请选择二级单位名称"
                :filter-option="false"
                @search="(value) => handeleSearch(value, 'ejdw')"
              >
                <a-spin v-if="fetching" slot="notFoundContent" size="small" />
                <a-select-option v-for="d in dataEjdw" :key="d.value">
                  {{ d.label }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
               <a-input
                @click.native="openOrganModelParam('departModalxmmc','项目名称')"
                readOnly
                v-model="model.xmmc"
                placeholder="请选择工程名称"
                style="width: 280px"
              />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目类型">
                <j-dict-select-tag
                  :maxTagCount="3"
                  class="select-multiple-notExpend"
                  placeholder="请选择项目类型"
                  v-model="model.xmlx"
                  dictCode="jjwj_xmlx_text"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目状态">
                <j-dict-select-tag
                  :maxTagCount="2"
                  placeholder="请选择项目状态"
                  v-model="model.xmzt"
                  dictCode="jjwj_xmzt_text"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="业主类别">
                <j-dict-select-tag
                  :maxTagCount="2"
                  class="select-multiple-notExpend"
                  placeholder="请选择业主类别"
                  style="width: 296px"
                  v-model="model.yzlb"
                  dictCode="jjwj_yzlb_jn_text"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否已列入股份公司专项治理清单">
                <j-dict-select-tag
                  placeholder="请选择是否已列入股份公司专项治理清单"
                  v-model="model.ifzxzl"
                  dictCode="yes_no_text"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="竣工验收日期">
                <a-month-picker
                  placeholder="请选择年月"
                  format="YYYY年MM月"
                  value-format="yyyy年MM月"
                  v-model="model.jgysrqText"
                  style="width: 100%"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="三级提交部门">
                <j-select-depart
                  v-model="queryParam.deptId"
                  :trigger-change="true"
                  customReturnField="id"
                  style="width: 100%"
                ></j-select-depart>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="二级提交部门">
                <j-select-depart
                  v-model="queryParam.lastDeptId"
                  :trigger-change="true"
                  customReturnField="id"
                  style="width: 100%"
                ></j-select-depart>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="8" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button :disabled="editingKey !== ''" type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
              <a-button
                :disabled="editingKey !== ''"
                type="primary"
                icon="download"
                @click="OnExportList"
                style="margin: 0px 8px"
              >
                导出
              </a-button>
              <a-upload
                name="file"
                :showUploadList="false"
                :multiple="false"
                :headers="tokenHeader"
                :action="importExcelUrl"
                :before-upload="beforeUpload"
                @change="handleImportExcel"
                accept=".docx, .doc, .xlsx, .xls, .pdf, .jpeg, .png"
              >
                <a-button :loading="upLoading" :disabled="editingKey !== ''|| upLoading" type="primary" icon="import">导入</a-button>
              </a-upload>
              <a-button
                v-if="OrgLevel != '1'"
                :disabled="!(reportSelectIds.length > 0 && editingKey == '')"
                type="primary"
                @click="SubmitDataId(5)"
                style="margin: 0px 8px"
              >
                一键提交</a-button
              >
              <a style="margin-left: 8px" @click="handleToggleSearch">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class="jjwjsj-title">
      <span>股份公司指挥部专项审计调查表</span>
    </div>
    <!-- 列表区域 -->
    <div>
      <div class="inforMation"><span>单位名称：</span></div>
      <a-table
        ref="table"
        size="middle"
        bordered
        class="edit-list"
        rowKey="id"
        :row-selection="rowSelection"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
        :scroll="{ x: 4000, y: 350 }"
      >
        <span slot="endTimeTitleA">截至2022年9月末业主对总包部计价</span>
        <span slot="endTimeTitleB">截至2022年9月末总包部对参建单位计价情况</span>
        <span slot="endTimeTitleC">截至2022年9月末债权债务及资金收支情况</span>

        <!--  表格中文字部分 -->
        <template v-for="col1 in ellipsisColList" :slot="col1" slot-scope="text, record">
          <div :key="col1">
            <a-input
              v-if="record.editable && ['yzmc', 'cjdwjc', 'reason', 'remark'].indexOf(col1) == -1"
              :value="text"
              @change="(e) => handleChangeInput(e.target.value, record.id, col1)"
            ></a-input>
            <a-textarea
              v-else-if="record.editable && ['yzmc', 'cjdwjc', 'reason', 'remark'].indexOf(col1) != -1"
              :value="text"
              @change="(e) => handleChangeInput(e.target.value, record.id, col1)"
            ></a-textarea>
            <j-ellipsis
              v-else-if="['yzmc', 'cjdwjc', 'reason', 'remark'].indexOf(col1) != -1"
              :value="text"
              :length="8"
            />
            <span v-else>{{ text }}</span>
          </div>
        </template>

        <!-- 表格中日期部分 -->
        <template v-for="col2 in dateColList" :slot="col2" slot-scope="text, record">
          <div :key="col2">
            <a-date-picker
              v-if="record.editable"
              :value="text"
              mode="month"
              placeholder="请选择年月"
              format="YYYY年MM月"
              value-format="yyyy年MM月"
              :open="yearPickShow == col2"
              style="width: 100%"
              @panelChange="
                (value, mode) => {
                  yearPickShow = col2
                  handleChangeInput(value, record.id, col2, 'date')
                }
              "
              @openChange="
                (status) => {
                  handleOpenChange(status ? col2 : '')
                }
              "
              @change="
                (date, value) => {
                  handleChangeInput(value, record.id, col2, 'date')
                }
              "
            />
            <span v-else>{{ text }}</span>
          </div>
        </template>

        <!-- 表格中数字部分 -->
        <template v-for="col3 in numColList" :slot="col3" slot-scope="text, record">
          <div :key="col3" v-if="record.totalName != '合计' && !record.serialnumber">
            <a-input-number
              style="width: 100%"
              :precision="2"
              v-if="record.editable"
              :value="text"
              @change="(value) => handleChange(value, record.id, col3, 'float')"
            ></a-input-number>
            <span v-else>{{ text }}</span>
          </div>
          <div :key="col3" v-else style="width: 100%; text-align: center">
            {{ text }}
          </div>
        </template>

        <!--  表格中下拉框部分 -->
        <template v-for="col4 in SelectColList" :slot="col4" slot-scope="text, record">
          <div :key="col4">
            <SelectVfor
              v-if="record.editable"
              :value="text"
              :data="SeletctAllData[col4]"
              @SelectChange="(value) => handleChangeInput(value, record.id, col4)"
            ></SelectVfor>
            <span v-else>{{ text }}</span>
          </div>
        </template>

        <template v-slot:action="text, record">
          <div v-if="record.totalName !== '合计' && !record.serialnumber" class="editable-row-operations">
            <span v-if="record.editable">
              <a @click="() => save(record.id)">保存</a>
              <a-divider type="vertical" />
              <a-popconfirm title="是否舍弃本次编辑内容？" @confirm="() => cancel(record.id)">
                <a>取消</a>
              </a-popconfirm>
            </span>
            <span v-else>
              <a :disabled="editingKey !== ''" @click="() => edit(record.id)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm
                :disabled="editingKey !== ''"
                title="是否确认删除？"
                @confirm="
                  () => {
                    Delete(record)
                  }
                "
              >
                <a>删除</a>
              </a-popconfirm>
            </span>
          </div>
        </template>
      </a-table>
      <div class="table-pagination" v-if="total > 0">
        <a-pagination
          v-bind="ipagination"
          :total="total"
          @showSizeChange="onShowSizeChange"
          @change="handleTableChange"
        />
      </div>
    </div>
    <AssistDrawerGfgs />
    <SelectDepat
      ref="departModalxmmc"
      :depurl="searchUrl.gcmc"
      @getdata="
        (data) => {
          getDataParam(data, 'xmmc')
        }
      "
    />
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SelectVfor from '@/views/sj/sjxxzhbb/jjwjsj/mixins/SelectVfor'
import AssistDrawerGfgs from '@/views/sj/sjxxzhbb/component/AssistDrawerGfgs.vue'
import { CommonMixin } from '@/views/sj/sjxxzhbb/jjwjsj/mixins/common.js'
import { deleteAction, getAction, downFile, getFileAccessHttpUrl, httpAction } from '@/api/manage'
import SelectDepat from '@/views/sj/sjxxzhbb/jjwjsj/mixins/SelectDepat'
import columns from './indexColumns'
export default {
  mixins: [JeecgListMixin, CommonMixin],
  components: { SelectVfor, AssistDrawerGfgs,SelectDepat},
  data() {
    return {
      columns: columns(this),
      importExcelUrl: `${window._CONFIG['domianURL']}/sjxxzhbb/gfgszbb/importExcel`,
      url: {
        list: '/sjxxzhbb/gfgszbb/list',
        hjlist: '/sjxxzhbb/gfgszbb/dataSum',
        exportList: 'sjxxzhbb/gfgszbb/exportXls',
        isExistenceExcel: '/sjxxzhbb/gfgszbb/isCurDeptImport',
        delete: '/sjxxzhbb/gfgszbb/deleteById',
        saveRowData: '/sjxxzhbb/gfgszbb/edit',
      },
      searchUrl: {
        ejdw: '/sjxxzhbb/gfgszbb/querySecondDept',
        gcmc: '/sjxxzhbb/gfgszbb/queryProName',
      },
      targetColListIndex: 2,
      editingKey: '',
      ellipsisColList: ['gcszd', 'yzmc', 'cjdwjc', 'reason', 'jsyjyjxkh', 'remark'],
      dateColList: ['htydrq', 'wgrq', 'sjkgrq', 'jgysrq', 'tgrq', 'ygjjrq'],
      numColList: ['yjj', 'dpfbgsp', 'hte', 'yjjbgtc', 'ywwjbgtc', 'sjgck', 'cjdwgck', 'yszkGck', 'cqyskGck'],
      yearPickShow: '',
      SelectColList: ['xmzt', 'xmlx', 'yzlb', 'ifzxzl'],
      SeletctAllData: {
        xmzt: ['久竣未结', '已竣未结', '已竣已结'],
        xmlx: ['铁路', '公路', '城轨', '市政', '房建', '水利水电', '其他'],
        yzlb: ['地方政府', '国有企业', '民营企业'],
        ifzxzl: ['是', '否'],
      },
      model:{
        xmmc:""
      }
    }
  },
  mounted() {
    this.getDataGcmcName()
  },
  methods: {
    // 表头查询
    searchQuery() {
      Object.keys(this.model).map((i) => {
        this.queryParam[i] =
          this.model[i] == null ? null : typeof this.model[i] == 'object' ? this.model[i].join(',') : this.model[i]
        if (i == 'sjjgysText' || i == 'tgrqText' || i == 'jgysrqText') {
          this.queryParam[i] = this.queryParam[i] ? this.queryParam[i] + '01日' : undefined
        }
      })
      // this.loadData()
      this.EnhanceLoad()
    },

    // 保存
    save(id) {
      let NewData = [...this.dataSource]
      let targetRowData = NewData.find((item) => id === item.id)
      let flag = ''

      let NameOfFileName = {
        xmlx: '项目类型',
        yzlb: '业主类别',
        xmzt: '项目状态（久竣未结/已竣未结/已竣已结）',
        ifzxzl: '是否已列入股份公司专项治理清单',
      }

      this.SelectColList.map((item) => {
        if (!targetRowData[item]) {
          flag += NameOfFileName[item] + '、'
        }
      })

      if (!targetRowData['jgysrq'] && !targetRowData['tgrq']) {
        this.$message.error('竣工验收日期和停工日期必须至少填写其中一个')
        return
      }

      if (flag == '') {
        this.editingKey = ''
        delete targetRowData.editable
        this.SaveEditRowData(targetRowData)
      } else {
        this.$message.error(flag + '下拉选项为必填项')
      }
    },
  },
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '~@views/sj/sjxxzhbb/css/baobiaotable.less';
</style>